using System.ComponentModel.DataAnnotations;

namespace AdminSG3L.Domain.Entities;

/// <summary>
/// 日志实体
/// </summary>
public class AppLog : EntityBase
{
    /// <summary>
    /// 日志时间，必填
    /// </summary>
    public DateTime Timestamp { get; private set; }
    /// <summary>
    /// 日志级别，必填
    /// </summary>
    public string Level { get; private set; }
    /// <summary>
    /// 日志内容，必填
    /// </summary>
    public string Message { get; private set; }
    /// <summary>
    /// 异常信息，可选
    /// </summary>
    public string? Exception { get; private set; }
    /// <summary>
    /// 额外属性，可选
    /// </summary>
    public string? Properties { get; private set; }
    /// <summary>
    /// 日志事件，可选
    /// </summary>
    public string? LogEvent { get; private set; }

    /// <summary>
    /// 私有构造函数，仅限工厂方法调用
    /// </summary>
    private AppLog(DateTime timestamp, string level, string message)
    {
        Timestamp = timestamp;
        Level = level;
        Message = message;
    }

    /// <summary>
    /// 创建AppLog对象的工厂方法
    /// </summary>
    /// <param name="timestamp">日志时间</param>
    /// <param name="level">日志级别</param>
    /// <param name="message">日志内容</param>
    /// <param name="exception">异常信息</param>
    /// <param name="properties">额外属性</param>
    /// <param name="logEvent">日志事件</param>
    /// <param name="description">描述</param>
    /// <returns>AppLog对象</returns>
    public static AppLog Create(DateTime timestamp, string level, string message, string? exception = null, string? properties = null, string? logEvent = null, string? description = null)
    {
        return new AppLog(timestamp, level, message)
        {
            Exception = exception,
            Properties = properties,
            LogEvent = logEvent,
            Description = description
        };
    }
}
